package com.xy.type6;


/**
 * @author 谢阳
 * @version 1.8.0_131
 * @date 2022/6/9 19:33
 * @description 静态内部类 （内部类装载时线程安全）
 */
public class SingletonTest {
    public static void main(String[] args) {
        Singleton instance1 = Singleton.getInstance();
        Singleton instance2 = Singleton.getInstance();
        System.out.println(instance1 == instance2);
    }
}

class Singleton  {
    private Singleton(){}

    private static class SingletonInstance {
        private static final Singleton INSTANCE = new Singleton();
    }


    public static Singleton getInstance(){
        return SingletonInstance.INSTANCE;
    }

}
